{template header}
<style type="text/css">
    .bg{display:none;position:fixed;width:100%;height:100%;background:#000;z-index:2;top:0;left:0;opacity:0.7;}
</style>
<h4 style="padding-left:10px;;">
    <a href="?c=adminErp&a=getErpProductList"><span>库存列表</span></a>
    >>
    <a href="?c=adminErp&a=addErpProductList"><span>新增货品</span></a>
</h4>
<script type="text/javascript">
    function uploadImage() {
        if($("#imgFile").val() != '') $("#upload_form").submit();
    }
    function upload_frame_load() {
        var data = $(window.frames['upload_frame'].document.body).html();
        if(data) {
            data = eval('(' + data + ')');
            //console.log(data);return false;
            if(data.status=='ok'){
                var _this= $('#showImage');_num = _this.find('img').length;
                var _html = '';
                if (_num && (_num % 5) == 0) {
                    _html +='<br />';
                }
                 _html +=
                        '<span style="margin: 10px  10px 10px 10px">'
                        +'<img src="'+ data.image+'" style="width: 100px;height: 100px;">'
                        +'<input type="hidden" name="image[]" value="'+data.image+'" />'
                        +'</span>'
                        +'<span class="btn btn-primary delimages" >删除</span>';

                $('#showImage').append(_html);
            }else{
                alert(data.error_msg);
            }
        }
    }
</script>
<div id="fream">
    <form id="upload_form" method="post" action="?c=adminErp&a=ajaxUploadImage" target="upload_frame" enctype="multipart/form-data">
        <input type="file" name="imgFile" id="imgFile" style="display:none;" onchange="uploadImage();">
    </form>
    <iframe id="upload_frame" name="upload_frame" style="display:none" onLoad="upload_frame_load();"></iframe>
</div>
<form class="form-horizontal"  action="?c=adminErp&a=addErpProduct"  id="tr_form">
    <div class="control-group">
        <label class="control-label" >货品名：</label>
        <div class="controls">
            <input type="text" value="" name="name" placeholder="货品名" />
            建议控制在20个汉字长度内
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" >运费：</label>
        <div class="controls">
            <input type="text" value="0" name="express_fee" placeholder="运费" />
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" >类别：</label>
        <div class="controls">
            <select name="cid">
                <option value="0">全部</option>
                {if count($arrCategoryList)>0}
                {loop $arrCategoryList $k $v}
                <option value="{$v['id']}">{$v['title']}</option>
                {/loop}
                {/if}
            </select>
        </div>
    </div>

    <div class="control-group">
        <label class="control-label" >  规格图片：</label>
        <div class="controls">
            <button type="button" id="file_upload_btn" class="btn btn-primary" onclick="$('#imgFile').trigger('click')">
                <i class="ace-icon fa fa-cloud-upload bigger-110"></i>上传图片
            </button>
            建议使用正方形图片，如100*100
        </div>
    </div>

    <div class="control-group">
        <div class="controls" id="showImage">
        </div>
    </div>
    <div class="control-group">
        <div class="controls">
            <span class="btn btn-primary" type="button" id="qd">确定</span>
        </div>
    </div>
</form>
{template footer}
<script type="text/javascript">
    $(document).on("click",".delimages", function () {
        var _this=$(this),_del = $(this).prev('span');
        _del.remove();
        _this.remove();
    })
    $('#qd').on('click',function(){
        $.ajax({
            type:'POST',
            url:$('#tr_form').attr('action'),
            data:$('#tr_form').serialize(),
            dataType:'json',
            success:function(d){
                if(d.status=='ok'){
                    alert(d.error_msg);
                    window.location.href=d.url;
                }else{
                    alert(d.error_msg);
                }
            }
        })
    })
</script>